package com.danhuang.cloud.danhuangdaily.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.danhuang.cloud.danhuangcore.annotation.DanHuang;
import com.danhuang.cloud.danhuangcore.entity.AlbumDTO;
import com.danhuang.cloud.danhuangcore.model.DhRes;
import com.danhuang.cloud.danhuangdaily.service.PhotoService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;

@Validated
@RestController
@RequestMapping("/photo")
public class PhotoController {

    @Resource
    private PhotoService photoService;

    @GetMapping("/album/list")
    public DhRes albumList(HttpServletRequest request){
        return photoService.albumList(request);
    }


    @DanHuang
    @PostMapping("/album/create")
    public DhRes albumCreate( @Valid @RequestBody AlbumDTO albumDTO){
        return photoService.albumCreate(albumDTO);
    }


    @GetMapping("/album/detail")
    public DhRes albumDetail(HttpServletRequest request, Page page, @NotBlank(message="albumId不能为空") @RequestParam String albumId){
        return photoService.albumDetail(request, page, albumId);
    }

    @DanHuang
    @PostMapping("/photo/upload")
    public DhRes photoUpload(@NotBlank(message="albumId不能为空") @RequestParam String albumId
            , @NotBlank(message="path不能为空") String path, @RequestPart MultipartFile file, String cover){
        return photoService.photoUpload(albumId,path, file, cover);
    }


    @PostMapping("/photo/big")
    public DhRes photoBig(@NotBlank(message="photoId不能为空") @RequestParam String photoId){
        return photoService.photoBig(photoId);
    }

    @DanHuang
    @PostMapping("/photo/test")
    public DhRes photoUploadtest(@NotBlank(message="albumId不能为空") @RequestParam String albumId, @NotBlank(message="path不能为空") String path){
        return photoService.test(albumId,path);
    }

    @GetMapping("/photo/down")
    public  byte[]  photoDown( @NotBlank(message="path不能为空") String path){
        return photoService.photoDown(path);
    }
}
